home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / GMS / Source / Asm / Chunky / 020.Simple.s < prev    next >
Encoding:
Text File  |  1997-05-11  |  10.3 KB  |  334 lines

  1. ;===================================================================================;
  2. ;                                 CHUNKY8 EMULATOR
  3. ;===================================================================================;
  4. ;This c2p routine is quite slow as it uses simple bit testing/setting
  5. ;instructions.  It has an advantage of no restrictions (any screen width/height is
  6. ;okay).
  7.  
  8. CHUNKYMEM =    MEM_CLEAR    ;<- Fast memory.
  9.  
  10.     INCDIR    "INCLUDES:"
  11.     INCLUDE    "exec/libraries.i"
  12.     INCLUDE    "exec/initializers.i"
  13.     INCLUDE    "exec/resident.i"
  14.     INCLUDE    "exec/exec_lib.i"
  15.     INCLUDE    "hardware/custom.i"
  16.     INCLUDE    "games/games.i"
  17.     INCLUDE    "games/games_lib.i"
  18.     INCLUDE    "games/debug.i"
  19.  
  20. CALL    MACRO
  21.     jsr    _LVO\1(a6)
  22.     ENDM
  23.  
  24. ;===================================================================================;
  25. ;                                  MONITOR DRIVER
  26. ;===================================================================================;
  27.  
  28.     STRUCTURE    ChunkyBase,LIB_SIZE
  29.     ULONG    CHK_SegList
  30.     LABEL    CHKBase_SIZEOF
  31.  
  32.     SECTION    "Chunky8",CODE
  33.  
  34. LibPriority =     0
  35.  
  36. CleanExit:        ;If the user tries to run the library, we
  37.     moveq    #$00,d0    ;don't want to crash...
  38.     rts
  39.  
  40. InitDescrip:
  41.     dc.w    RTC_MATCHWORD    ;UWORD rt_matchword
  42.     dc.l    InitDescrip,EndCode    ;APTR  rt_matchtag, rt_endskip
  43.     dc.b    RTF_AUTOINIT,GMSVersion    ;UBYTE rt_flags, rt_version
  44.     dc.b    NT_LIBRARY,LibPriority    ;UBYTE rt_type, rt_pri
  45.     dc.l    LibName,IDString,Init    ;APTR  rt_name, rt_idstring, rt_init
  46.  
  47. LibName:
  48.     dc.b    "020.Simple",0
  49.     even
  50.     dc.b    "$VER: "
  51. IDString:
  52.     dc.b    "Chunky 8 Emulator V0.6",10,0
  53.     even
  54.  
  55. Init:    dc.l    CHKBase_SIZEOF,FunctionTable,DataTable,InitRoutine
  56.  
  57. FunctionTable:
  58. FT:    dc.w    -1,Open-FT,Close-FT,Expunge-FT,Null-FT
  59.     dc.w    LIB_emuRemapFunctions-FT
  60.     dc.w    LIB_emuInitRefresh-FT
  61.     dc.w    LIB_emuFreeRefresh-FT
  62.     dc.w    LIB_emuRefreshScreen-FT
  63.     dc.w    -1
  64.  
  65. DataTable:
  66.     INITBYTE LN_TYPE,NT_LIBRARY
  67.     INITLONG LN_NAME,LibName
  68.     INITBYTE LIB_FLAGS,LIBF_SUMUSED!LIBF_CHANGED
  69.     INITWORD LIB_VERSION,GMSVersion
  70.     INITWORD LIB_REVISION,GMSRevision
  71.     INITLONG LIB_IDSTRING,IDString
  72.     dc.l    0
  73.     even
  74.  
  75. ;===================================================================================;
  76. ;                              INITIALISATION ROUTINE
  77. ;===================================================================================;
  78. ;Requires: a0 = SegList
  79. ;       d0 = Library Base.
  80.  
  81. InitRoutine:
  82.     MOVEM.L    D1-D7/A0-A6,-(SP)    ;SP = Save registers.
  83.     move.l    d0,a5    ;a5 = Store pointer to our base.
  84.     move.l    d0,CHKBase    ;ma = Save pointer to our base.
  85.     move.l    a0,CHK_SegList(a5)    ;a5 = Save pointer to SegList.
  86.     move.l    CHKBase(pc),d0    ;d0 = Return library pointer.
  87. .error    MOVEM.L    (SP)+,D1-D7/A0-A6    ;SP = Return registers.
  88.     rts
  89.  
  90. ;===================================================================================;
  91. ;                                   OPEN LIBRARY
  92. ;===================================================================================;
  93.  
  94. Open:    addq.w    #1,LIB_OPENCNT(a6)    ;Increment lib count.
  95.     bclr    #LIBB_DELEXP,LIB_FLAGS(a6)
  96.     move.l    a6,d0    ;Return library base.
  97.     rts
  98.  
  99. ;===================================================================================;
  100. ;                                  CLOSE LIBRARY
  101. ;===================================================================================;
  102.  
  103. Close:    moveq    #$00,d0    ;This is called whenever someone closes
  104.     subq.w    #1,LIB_OPENCNT(a6)    ;our library.
  105.     bne.s    .Exit
  106.     btst    #LIBB_DELEXP,LIB_FLAGS(a6)
  107.     beq.s    .Exit
  108.     bsr.s    Expunge
  109. .Exit    rts
  110.  
  111. ;===================================================================================;
  112. ;                               EXPUNGE THE LIBRARY
  113. ;===================================================================================;
  114.  
  115. Expunge:
  116.     MOVEM.L    D1-D7/A0-A6,-(SP)    ;SP = Save all registers.
  117.     move.l    a6,a5    ;a5 = Our library base.
  118.     tst.w    LIB_OPENCNT(a5)    ;a5 = Do any programs have us open?
  119.     beq.s    .expunge    ;>> = No, so it's safe to expunge ourselves.
  120.     bset    #LIBB_DELEXP,LIB_FLAGS(a5)
  121.     MOVEM.L    (SP)+,D1-D7/A0-A6    ;SP = Return all registers.
  122.     moveq    #$00,d0
  123.     rts
  124.  
  125. .expunge
  126.     move.l    ($4).w,a6    ;a6 = ExecBase.
  127.     move.l    CHK_SegList(a5),d2    ;d2 = Our segment list.
  128.     move.l    a5,a1    ;a1 = Our library base.
  129.     CALL    Remove    ;>> = Remove it.
  130.     move.l    a5,a1    ;a1 = Our library base.
  131.     moveq    #$00,d0    ;d0 = 00
  132.     move.w    LIB_NEGSIZE(a5),d0    ;d0 = LIB_NEGSIZE(base)
  133.     sub.l    d0,a1    ;a1 = (base)-LIB_NEGSIZE
  134.     add.w    LIB_POSSIZE(a5),d0    ;d0 = (LIB_NEGSIZE)+LIB_POSSIZE
  135.     CALL    FreeMem    ;>> = Free the memory.
  136.     move.l    d2,d0    ;d0 = Pointer to segment list.
  137.     MOVEM.L    (SP)+,D1-D7/A0-A6    ;SP = Return all registers, d0 = seglist.
  138.     rts
  139.  
  140. ;===================================================================================;
  141. ;                                    DO NOTHING
  142. ;===================================================================================;
  143.  
  144. Null:    moveq    #$00,d0
  145.     rts
  146.  
  147. ;===================================================================================;
  148. ;                                FUNCTION REMAPPING
  149. ;===================================================================================;
  150. ;Function: Ignore this function, we will only use it to grab the GMSBase.
  151. ;Requires: d0 = GamesBase.
  152. ;       a6 = Chunky Base.
  153. ;Returns:  Nothing.
  154.  
  155. LIB_emuRemapFunctions:
  156.     move.l    d0,GMSBase    ;ma = Save the GMSBase.
  157.     rts
  158.  
  159. ;===================================================================================;
  160. ;                             INITIALISE C2P ALGORITHM
  161. ;===================================================================================;
  162. ;Function: Initialise the C2P algorithm for emuRefreshScreen().  Note how if the
  163. ;       screen is double buffered, we do not allocate a second chunky buffer.
  164. ;       The reason is because a second planar display buffer already exists, so
  165. ;       having a second chunky buffer has no benefit.
  166. ;Requires: a0 = GameScreen
  167. ;       a6 = Chunky Base.
  168. ;Returns:  d0 = ErrorCode.
  169.  
  170. LIB_emuInitRefresh:
  171.     MOVEM.L    D1-D7/A0-A6,-(SP)    ;SP = Return used registers.
  172.     move.l    GMSBase(pc),a6    ;a6 = GMSBase.
  173.  
  174.     ;Move the planar screen displays (allocated in AddScreen()) to
  175.     ;GS_EMemPtrX.
  176.  
  177.     move.l    GS_MemPtr1(a0),GS_EMemPtr1(a0)
  178.     move.l    GS_MemPtr2(a0),GS_EMemPtr2(a0)
  179.     move.l    GS_MemPtr3(a0),GS_EMemPtr3(a0)
  180.  
  181.     ;Allocate the chunky memory, place it in GS_MemPtrX fields and store
  182.     ;the pointers in GS_EFreeX fields to free it later.
  183.  
  184.     move.w    GS_PicWidth(a0),d0    ;d0 = PicWidth
  185.     mulu    GS_PicHeight(a0),d0    ;d0 = (PicWidth)*PicHeight
  186.     moveq    #CHUNKYMEM,d1    ;d1 = Memory Type (see definition).
  187.     CALL    AllocMemBlock    ;>> = Go get the chunky memory.
  188.     move.l    d0,GS_EFree1(a0)    ;a4 = Store chunky buffer for freemem.
  189.     move.l    d0,GS_MemPtr1(a0)    ;a0 = Store chunky buffer #1.
  190.     beq.s    .error    ;>> = Memory allocation error.
  191.  
  192.     move.l    GS_Attrib(a0),d2    ;d2 = Screen attributes.
  193.     and.l    #DBLBUFFER,d2    ;d2 = Double buffer?
  194.     beq.s    .done    ;>> = No, finished.
  195.     move.l    d0,GS_MemPtr2(a0)    ;a0 = Store chunky buffer #1.
  196.  
  197. .done    MOVEM.L    (SP)+,D1-D7/A0-A6    ;SP = Return used registers.
  198.     moveq    #ERR_SUCCESS,d0
  199.     rts
  200.  
  201. .error    MOVEM.L    (SP)+,D1-D7/A0-A6    ;SP = Return used registers.
  202.     moveq    #ERR_FAILED,d0
  203.     rts
  204.  
  205. ;===================================================================================;
  206. ;                            DE-INITIALISE C2P ALGORITHM
  207. ;===================================================================================;
  208. ;Function: Free any allocations we made for the C2P routine.
  209. ;Requires: a0 = GameScreen
  210. ;       a6 = Chunky Base.
  211. ;Returns:  Nothing.
  212.  
  213. LIB_emuFreeRefresh:
  214.     MOVEM.L    D0/A6,-(SP)    ;SP = Save used registers.
  215.     move.l    GMSBase(pc),a6    ;a6 = GMSBase.
  216.     move.l    GS_EFree1(a0),d0    ;d0 = Screen memory 1 (C2P)
  217.     CALL    FreeMemBlock    ;>> = Free screen memory.
  218.     move.l    GS_EFree2(a0),d0    ;d0 = Screen memory 2 (C2P)
  219.     CALL    FreeMemBlock    ;>> = Free screen memory.
  220.     move.l    GS_EFree3(a0),d0    ;d0 = Screen memory 3 (C2P)
  221.     CALL    FreeMemBlock    ;>> = Free screen memory.
  222.     MOVEM.L    (SP)+,D0/A6    ;SP = Return used registers.
  223.     rts
  224.  
  225. ;===================================================================================;
  226. ;                              C2P CONVERSION ROUTINE
  227. ;===================================================================================;
  228. ;Function: Do the C2P process.
  229. ;Requires: a0 = GameScreen
  230. ;       a6 = Chunky Base.
  231. ;Returns:  Nothing.
  232.  
  233. LIB_emuRefreshScreen:
  234.     MOVEM.L    D0-D7/A0-A6,-(SP)    ;SP = Save used registers.
  235.     move.l    GMSBase(pc),a6    ;a6 = GMSBase.
  236.     move.w    GS_PicByteWidth(a0),d5    ;d5 = PicWidth            [320]
  237.     mulu    GS_PicHeight(a0),d5    ;d5 = (PicWidth)*PicHeight [320*256]
  238.  
  239.     move.w    GS_PicWidth(a0),d0    ;d0 = PicWidth            [320]
  240.     lsr.w    #3,d0    ;d0 = PicWidth/8 [planar]  [320/8]
  241.     mulu    GS_PicHeight(a0),d0    ;d0 = Size of a planar bitplane.
  242.  
  243.     move.l    GS_Attrib(a0),d1    ;d1 = GameScreen attributes
  244.     and.l    #DBLBUFFER|TPLBUFFER,d1    ;d1 = Double or triple buffered?
  245.     bne.s    .doubleandtriple    :>> = Yes.
  246.  
  247. .single    move.l    GS_EMemPtr1(a0),a1    ;a1 = Pointer to planar display.
  248.     move.l    GS_MemPtr1(a0),a0    ;a0 = Pointer to chunky buffer.
  249.     bra.s    .process
  250.  
  251. .doubleandtriple
  252.     move.l    GS_EMemPtr2(a0),a1    ;a1 = Pointer to planar display.
  253.     move.l    GS_MemPtr2(a0),a0    ;a0 = Pointer to chunky buffer.
  254.  
  255. .process
  256.     lea    (a1,d0.l*2),a2    ;a2 = Plane 2.
  257.     lea    (a2,d0.l*2),a3    ;a3 = Plane 4.
  258.     lea    (a3,d0.l*2),a4    ;a4 = Plane 6.
  259.     lea    (a4,d0.l),a5    ;a5 = Plane 7.
  260.     move.l    a0,a6    ;a6 = Start of chunky plane.
  261.     add.l    d5,a6    ;a6 = End of chunky plane.
  262.  
  263.     ;a0 = Chunky buffer
  264.     ;a1 = Plane 0
  265.     ;a1 = Plane 1
  266.     ;a2 = Plane 2
  267.     ;a2 = Plane 3
  268.     ;a3 = Plane 4
  269.     ;a3 = Plane 5
  270.     ;a4 = Plane 6
  271.     ;a5 = Plane 7
  272.     ;a6 = End of chunky plane.
  273.     ;
  274.     ;d6 = Chunky byte.
  275.     ;d7 = Pixel position in planar destination.
  276.  
  277. .copy    moveq    #8-1,d7    ;d7 = 8 pixels to copy across.
  278.     moveq    #$00,d1
  279.     moveq    #$00,d2
  280.     moveq    #$00,d3
  281.     moveq    #$00,d4
  282.     moveq    #$00,d5
  283.     clr.b    (a3,d0.l)
  284.     clr.b    (a4)
  285.     clr.b    (a5)
  286. .loop    move.b    (a0)+,d6    ;d6 = Chunky byte.
  287. .bit0    btst    #0,d6
  288.     beq.s    .bit1
  289.     bset    d7,d1
  290. .bit1    btst    #1,d6
  291.     beq.s    .bit2
  292.     bset    d7,d2
  293. .bit2    btst    #2,d6
  294.     beq.s    .bit3
  295.     bset    d7,d3
  296. .bit3    btst    #3,d6
  297.     beq.s    .bit4
  298.     bset    d7,d4
  299. .bit4    btst    #4,d6
  300.     beq.s    .bit5
  301.     bset    d7,d5
  302. .bit5    btst    #5,d6
  303.     beq.s    .bit6
  304.     bset    d7,(a3,d0.l)
  305. .bit6    btst    #6,d6
  306.     beq.s    .bit7
  307.     bset    d7,(a4)
  308. .bit7    btst    #7,d6
  309.     beq.s    .done
  310.     bset    d7,(a5)
  311. .done    dbra    d7,.loop    ;d7 = --1 and loop.
  312.  
  313.     move.b    d2,(a1,d0.l)
  314.     move.b    d1,(a1)+
  315.     move.b    d4,(a2,d0.l)
  316.     move.b    d3,(a2)+
  317.     move.b    d5,(a3)+
  318.     addq.w    #1,a4
  319.     addq.w    #1,a5
  320.     cmp.l    a0,a6
  321.     bne.s    .copy
  322.     MOVEM.L    (SP)+,D0-D7/A0-A6    ;SP = Return used registers.
  323.     rts
  324.  
  325. ;===================================================================================;
  326. ;                                       DATA
  327. ;===================================================================================;
  328.  
  329. GMSBase    dc.l    0
  330. CHKBase dc.l    0
  331.  
  332. ;-----------------------------------------------------------------------------------;
  333. EndCode:
  334.